# 
#  Makefile.am  Written by ChenJie
#
#	Description: This file defines the common things for Makefile.
#

# Build Tools, using g++ (not GCC) because its TYPE CONVERSION CHECK is more strong!!!!
CC			= g++ 
LD			= ld
AR			= ar
LINK			= g++
CPP			= g++ -E 
# '-g -rdynamic' is useful for debugging:
CFLAGS		= -DDEBUG -Wall -g -rdynamic
LIBS			= 
LDFLAGS		= -r
ARFLAGS		= -r -s -v


# Rules for compiling
.cpp.o:
	$(CC) $(CFLAGS)	-c -o $*.o $<
.c.o:
	$(CC) $(CFLAGS)	-c -o $*.o $<
.S.o:
	$(CC) $(CFLAGS) -c -o $*.o $<
.c.s:					
	$(CC) $(CFLAGS) -S -o $*.s $<
.s.o:
	$(CC) $(CFLAGS) -c -o $*.o $<

# Targets
.PHONY : all clean dep
all : $(TARGETS)

clean:
	for i in $(SUB_DIRS);do (cd $$i;make clean);done
	rm -f $(TARGETS) $(OBJECTS)

dep:
	for i in $(SUB_DIRS);do (cd $$i;make dep);done
	sed '/\#\#\# Dependencies/q' < Makefile > Makefile.deps
	if [ `echo *.c | cut -c1-3` != "*.c" ]; then ($(CPP) -M *.c) >> Makefile.deps;fi
	if [ `echo *.cpp | cut -c1-5` != "*.cpp" ]; then ($(CPP) -M *.cpp) >> Makefile.deps;fi
	if [ `echo *.S | cut -c1-3` != "*.S" ]; then ($(CPP) -M *.S) >> Makefile.deps;fi
	mv Makefile.deps Makefile

# A Makefile Sample:
#######################################################
# Makefile
#PROJECT_NAME=
#
#SOURCE_ROOT=.
#
#TARGETS=$(target1) $(target2)
#
#OBJECTS = $(target1_objs) $(target2_objs)
#
#SUB_DIRS=boot lib
#
#include $(SOURCE_ROOT)/Makefile.am
#
#
#backup: clean
#	(cd $(SOURCE_ROOT)/..; tar zcvf $(PROJECT_NAME).tar.gz src > $(PROJECT_NAME).tar.gz.map)
#
#$(target1): $(target1_objs)
#	$(LD) $(LDFLAGS) $(target1_objs) -o $(target1)
#
#$(target2): $(target2_objs)
#	nm $(OSIMAGE) | sort > $(SYSTEMMAP)
#
#boot/boot.o:
#	(cd boot; make)
#
#lib/lib.a:
#	(cd lib; make)
#
#### Dependencies:
#######################################################
